/**
 * 技师管理的UIComponents
 * @author: minzhang
 * @update: 2016-11-09
 */

import React, {PropTypes} from 'react';
import {connect} from 'dva';
import { Link } from 'dva/router';
import {Button, Table, Pagination} from 'antd';
import classnames from 'classnames';
import StoreSettingMenu from '../../components/StoreSetting/StoreSettingMenu';
import RoomsManageSearch from '../../components/RoomsManage/RoomsManageSearch';
import RoomsManageList from '../../components/RoomsManage/RoomsManageList';
import RoomsManageModal from '../../components/RoomsManage/RoomsManageModal';
import RoomsManageTypeModal from '../../components/RoomsManage/RoomsManageTypeModal';

function RoomsManage({location, dispatch, roomsManage}) {

    const {
        modalVisible, modalType, item, btnLoading, modalLoading,
        total, pageNumber, pageSize, loading, list,
				typeVisible, typeBtnLoading,
    } = roomsManage;

    // 搜索
    const roomsManageSearchProps = {
        onChange(changedFields) {
//            dispatch({
//                type: 'roomsManage/updateQuery',
//                payload: {
//                    query: {...query}
//                },
//            });
        },
        onSubmit(data) {
//            dispatch({
//                type: 'roomsManage/query',
//                payload: {
//                    pageNumber: 1,
//                    pageSize: pageSize
//                }
//            });
        }
    };

    // 新增/编辑
    const roomsManageModalProps = {
        title: modalType === 'create' ? '添加包间' : '编辑包间',
        item: modalType === 'create' ? {} : item,
        btnLoading,
        modalLoading,
        visible: modalVisible,
				onAddType() {
					dispatch({
						type: 'roomsManage/showTypeModal',
					});
				},
				onOkAndAdd(formData, fn) {
					dispatch({
						type: `roomsManage/${modalType}`,
						payload: {
								formData,
								fn,
								pageNumber: 1,
								pageSize,
						}
					});
				},
        onOk(formData, fn) {
					dispatch({
						type: `roomsManage/${modalType}`,
						payload: {
								formData,
								fn,
								pageNumber: 1,
								pageSize,
						}
					});
        },
        onCancel() {
					dispatch({
						type: 'roomsManage/hideModal',
					});
        },
    };

    // 包间列表
    const roomsManageListProps = {
        total,
        pageNumber,
        loading,
        pageSize,
        dataSource: list,
        onPageChange(page) {
					dispatch({
						type: 'roomsManage/query',
						payload: {
							pageNumber: page,
							pageSize,
						},
					});
        },
        onShowSizeChange(current, pageSize) {
					dispatch({
						type: 'roomsManage/query',
						payload: {
							pageNumber: current,
							pageSize,
						},
					});
        },
        onAdd() {
					dispatch({
						type: 'roomsManage/showModal',
					});
        },
        onDeleteItem(id) {
					dispatch({
						type: 'roomsManage/delete',
						payload: {
							id,
							pageNumber,
							pageSize,
						},
					});
        },
        onEditItem(id) {
					dispatch({
						type: 'roomsManage/detail',
						payload: {
							modalType: 'update',
							id,
						},
					});
        },
    };
	
		// 新建包间类型
		const roomsManageTypeModalProps = {
			typeVisible, 
			typeBtnLoading,
			onTypeOk(data) {
//				dispatch({
//					type: 'roomsManage/detail',
//					payload: {
//						modalType: 'update',
//						id,
//					},
//				});
			},
			onTypeCancel() {
				dispatch({
					type: 'roomsManage/hideTypeModal',
				});
			},
		};
	
    return (
			<div>
				<StoreSettingMenu current={location.pathname}/>
				<div className="page-content" style={{height: 'calc(100vh - 142px)', padding: 20}}>
					<RoomsManageSearch {...roomsManageSearchProps} />
					<RoomsManageList {...roomsManageListProps} />
					<RoomsManageModal {...roomsManageModalProps} />
					<RoomsManageTypeModal {...roomsManageTypeModalProps} />
				</div>
			</div>
    );
}

RoomsManage.propTypes = {
    location: PropTypes.object,
    dispatch: PropTypes.func,
    roomsManage: PropTypes.object,
};

export default connect(({roomsManage}) => ({roomsManage}))(RoomsManage);